package Views;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import javax.swing.JTextField;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JTextArea;
import javax.swing.JComboBox;

public class AddIngredientDialog extends JFrame implements ActionListener {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private static final String ADD = "Add";
	private static final String CANCEL = "Cancel";
	
	
	private final JPanel dialogPnl = new JPanel();
	private JTextField textField;
	private JTextField textField_1;
	private JTextField nameTxt;


	/**
	 * Create the dialog.
	 */
	public AddIngredientDialog() {
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(new BorderLayout());
		dialogPnl.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(dialogPnl, BorderLayout.NORTH);
		GridBagLayout gbl_dialogPnl = new GridBagLayout();
		gbl_dialogPnl.rowWeights = new double[]{0.0, 0.0, 0.0, 1.0};
		gbl_dialogPnl.columnWeights = new double[]{0.0, 1.0, 1.0};
		dialogPnl.setLayout(gbl_dialogPnl);
		addButtons();
		getContentPane().add(dialogPnl, BorderLayout.CENTER);
		
		JLabel nameLbl = new JLabel("Name:");
		GridBagConstraints gbc_nameLbl = new GridBagConstraints();
		gbc_nameLbl.anchor = GridBagConstraints.EAST;
		gbc_nameLbl.insets = new Insets(0, 0, 5, 5);
		gbc_nameLbl.gridx = 0;
		gbc_nameLbl.gridy = 0;
		dialogPnl.add(nameLbl, gbc_nameLbl);
		
		nameTxt = new JTextField();
		GridBagConstraints gbc_nameTxt = new GridBagConstraints();
		gbc_nameTxt.insets = new Insets(0, 0, 5, 5);
		gbc_nameTxt.fill = GridBagConstraints.HORIZONTAL;
		gbc_nameTxt.gridx = 1;
		gbc_nameTxt.gridy = 0;
		dialogPnl.add(nameTxt, gbc_nameTxt);
		nameTxt.setColumns(10);
		
		JLabel typeLbl = new JLabel("Type:");
		GridBagConstraints gbc_typeLbl = new GridBagConstraints();
		gbc_typeLbl.anchor = GridBagConstraints.EAST;
		gbc_typeLbl.insets = new Insets(0, 0, 5, 5);
		gbc_typeLbl.gridx = 0;
		gbc_typeLbl.gridy = 1;
		dialogPnl.add(typeLbl, gbc_typeLbl);
		
		JComboBox typeCBox = new JComboBox();
		GridBagConstraints gbc_typeCBox = new GridBagConstraints();
		gbc_typeCBox.insets = new Insets(0, 0, 5, 5);
		gbc_typeCBox.fill = GridBagConstraints.HORIZONTAL;
		gbc_typeCBox.gridx = 1;
		gbc_typeCBox.gridy = 1;
		dialogPnl.add(typeCBox, gbc_typeCBox);
		
		JLabel descLbl = new JLabel("Description (250 characters):");
		GridBagConstraints gbc_descLbl = new GridBagConstraints();
		gbc_descLbl.insets = new Insets(0, 0, 5, 5);
		gbc_descLbl.gridx = 1;
		gbc_descLbl.gridy = 2;
		dialogPnl.add(descLbl, gbc_descLbl);
		
		JTextArea descTxt = new JTextArea();
		GridBagConstraints gbc_descTxt = new GridBagConstraints();
		gbc_descTxt.gridwidth = 3;
		gbc_descTxt.fill = GridBagConstraints.BOTH;
		gbc_descTxt.gridx = 0;
		gbc_descTxt.gridy = 3;
		dialogPnl.add(descTxt, gbc_descTxt);
		
		revalidate();
		
	}
	
	private void addButtons() {
		JPanel btnPnl = new JPanel();
		btnPnl.setLayout(new FlowLayout());
		JButton addBtn = new JButton(ADD);
		addBtn.addActionListener(this);
		btnPnl.add(addBtn);
		
		JButton cnclBtn = new JButton(CANCEL);
		cnclBtn.addActionListener(this);
		btnPnl.add(cnclBtn);

		getContentPane().add(btnPnl, BorderLayout.SOUTH);
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		switch(arg0.getActionCommand()) {
		case ADD: System.out.println("ADD clicked"); break;
		case CANCEL: this.dispose(); break;
		}
		
	}
}
